<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function __construct(){
        parent::__construct();
        $this->checkpower();
    }
    public function index(){

		$this->display();
    }
    public function type(){
        if(IS_POST){
          
            M('articletype')->add($_POST);
        }
        $type=M('articletype')->select();
        $this->assign('type',$type);
        $this->display();
    }
    public function article(){
         $article=M('article')->select();
         $this->assign('article',$article);
         $this->display();
    }
    public function deletetype(){
        if(M('articletype')->where(array('id'=>I('id')))->delete()){
           M('article')->where(array('type'=>$id))->save(array('type'=>0));//该分类文章归为未分类
            
            $this->success('删除成功');
        }
        
    }
    public function deletearticle(){
        if(M('article')->where(array('id'=>I('id')))->delete()){
            $this->success('删除成功');
        }
    }
    public function user(){
        
        if(IS_POST){
         
            if(I('cansignup')==null)$_POST['cansignup']=0;
            $_POST['username']=session('username');
           
            if(!M('setting')->where(array('username'=>session('username')))->save($_POST))
            M('setting')->add($_POST);
            $this->success("保存成功");
        }else $this->display();
    }
    public function checkpower(){
        $user=session('username');
        if($user&&M('user')->where(array('username'=>$user))->getField("power")){
            return true;
        }else {
            $this->error('没有权限',U('Home/Login/index'));
        }
    }
    
}
